package com.water.weblog.module.jwt.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserDetailServiceImpl implements UserDetailsService {
    // 从数据库中查询
    // ...

    // 暂时先写死，密码为 water, 这里填写的密文，数据库中也是存储此种格式
    // authorities 用于指定角色，这里写死为 ADMIN 管理员
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return User.withUsername("water")
                .password("$2a$10$242Fob9BPNSPw/t7Ho01XOrBQbhmGzVEDV7pJ199AS/HkuSHVZpBq")
                .authorities("admin")
                .build();
    }
}
